// GroupPipe.h: interface for the CGroupPipe class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_GROUPPIPE_H__FD0F356F_D936_4C9C_9D61_2761E20E742D__INCLUDED_)
#define AFX_GROUPPIPE_H__FD0F356F_D936_4C9C_9D61_2761E20E742D__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "UePipe.h"
#include "UeList.h"

#include "DlgGroupPipe.h"

class CGroupPipe : public CUePipe  
{
public:
	CGroupPipe();
	virtual ~CGroupPipe();

public:
	void Draw(void);

protected:
	bool Set(void);
	
	//parameters
//	bool SetGroupParameter(void); 
	bool SaveAllPipesParameter(void);
	bool SavePipeParameter(CUeList lstPara, CString& strHandle);
//	void SaveBranchRelation(void);

	bool IsExistPipeParameter(CUeList lstPara, CString& strHandle);
	
	CUeList GetParaFromExistPipeList(int nIndex);
	CString GetPipeHandleFromExistPipeList(int nIndex);

	bool GetGroupPipeFromMap(CString strKey, CGroupPipeInfo*& pGp);
	bool GetGroupPipeFromMap(POSITION &pos, CGroupPipeInfo*& pGp);
	
	void GetPipeSNArray(void);

	//drawing
	void BeginDrawing(void);
	AcDbObjectId DrawLine(AcGePoint3d pt3Start, AcGePoint3d pt3End,
		CString strLayer, Adesk::UInt16 iColor);

	bool DrawGroupPipe(AcGePoint3d pt3Start, AcGePoint3d pt3End);
	bool DrawPipe(CGroupPipeInfo *pGp, AcGeVector3d vec3Level, ads_name &entPipe);

	//point
	bool GetStartPoint(AcGePoint3d &pt3Start);
	bool GetNextPoint(AcGePoint3d &pt3Start, AcGePoint3d &pt3Next);
	AcGePoint3d GetNextPoint(AcGePoint3d pt3Start, AcGeVector3d vec3Direction, double dbDisplacement);

	bool GetClosedEndPoint(ads_point &pt);
	bool GetBasePoint(ads_point &pt);
	bool GetBaseLinePoint(ads_point &pt);
	bool GetLevelPoint(AcGePoint3d pt3Start, ads_point &pt);
	bool GetDirectionPoint(MYCHAR cIn, AcGePoint3d pt3Start, ads_point &pt);
	bool GetTeeClosedPoint(AcGePoint3d pt3Start, ads_point &pt);
	bool GetPrePoint(ads_point &pt);

	AcGePoint3d CalPrePipeEndPoint(AcGePoint3d pt3CurPipeStart, CGroupPipeInfo *pGp);
	AcGePoint3d AdjustPrePipeEndPoint(AcGePoint3d pt3Start, CGroupPipeInfo *pGp);

	//
	void AdspointToAcgepoint3d(AcGePoint3d &pt3d, ads_point ptAds);
	void Acgepoint3dToAdspoint(ads_point &ptAds, AcGePoint3d pt3d);
	void Acgepoint3dToAcgevector3d(AcGeVector3d &vec3d, AcGePoint3d pt3d);
	void Acgevector3dToAcgepoint3d(AcGePoint3d &pt3d, AcGeVector3d vec3d);
	
	//pipe
	CString GetPipeIDFromPipeObj(CGroupPipeInfo *pGp);
	int GetPipeColorFromPipeObj(CGroupPipeInfo *pGp);
	double GetPipeWeightFromPipeObj(CGroupPipeInfo *pGp);
	double GetPipeDiameterFromPipeObj(CGroupPipeInfo *pGp);

	bool GroupPipeToSinglePipe(ads_name entPipe);

	CString GetBasePipeSN(void);
	int GetBasePipeIndex(void);  //get the index of base pipe from the m_arrPipeSN
	bool IsBasePipe(CString strPipeSN);

	bool IsPipeOK(AcGePoint3d pt3Start, AcGePoint3d pt3End);
	bool IsPipeDirectionOK(AcGeVector3d vec3CurDir, AcGeVector3d vec3PreDir);
	bool IsPipeLengthOK(AcGePoint3d pt3Start, AcGePoint3d pt3End);
	bool IsExistPipe();

	bool GetPrePipePoint(AcGePoint3d &pt3Pre);
	AcGeVector3d GetLastPipeDirection(void);

	//layer
	void CheckAllLayers(void);  //check all pipes' layer, if not exist, create it.

	//vector
	AcGeVector3d CalGroupArrangeDirectionVec(AcGePoint3d pt3Start, AcGePoint3d pt3End); //calculate direction vector
	AcGeVector3d SinAngleOfAxisAndPlane(AcGePlane plane);  //calculate sin(angle), angle is between the axis and plane 
	
	AcGeVector3d CalGroupPipeLevelVec(AcGePoint3d pt3Start, AcGePoint3d pt3End);  //calculate pipe level vector

	//handle
	bool SavePipeHandle(CGroupPipeInfo *pGp, AcGePoint3d pt3Start);
	CString GetObjHandle(AcDbObjectId idObj);
	bool GetBasePipeHandle(CString &strHandle);
	bool GetObjHandEnt(CString strHandle, ads_name &ent);

	//entity
	void DeleteAllEntity(CUeList lstEntity);
	bool GetPreObjID(void);


//****below methods may be available, don't delete it****//

/*	//info
	bool SavePipeInfo(CGroupPipeInfo *pGp);
	bool GetPipeInfo(CString strSN);
	bool SaveGroupInfo(void);
	bool GetGroupInfo(ads_name entPipe);
	
	//xdata
	bool SaveGroupInfoXdata(CString strHandle, CUeList lstGroupInfo);
	bool GetGroupInfoXdata(ads_name entPipe, CUeList &lstGroupInfo);
	bool SavePipeInfoXdata(CString strHandle, CUeList lstPipeInfo);
	bool GetPipeInfoXdata(ads_name entPipe, CUeList &lstPipeInfo);
	bool GetPipeInfoXdata(CString strHandle, CUeList &lstPipeInfo);
*/


private:
	CMapStringToOb m_mapGroupPipe;   //group pipe parameters
	CString m_strBasePipeSN;      //base pipe SN
	CStringArray m_arrPipeSN;   //all pipe SN
	int m_iGroupPipeAlignStyle;
	
	AcGeVector3d m_vec3GroupArrangeDir;  //group pipe arrange direction
	AcGeVector3d m_vec3GroupLevelDir;    //group level direction
	AcGeVector3d m_vec3PreGroupArrangeDir;

	CUeList m_lstAllPipesEnt;       //the list of all pipes' entity
	CUeList m_lstPipePoint;     //the list of all points which pipes' start and end

};

#endif // !defined(AFX_GROUPPIPE_H__FD0F356F_D936_4C9C_9D61_2761E20E742D__INCLUDED_)
